home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / doc / efun / regreplace < prev    next >
Text File  |  2001-05-25  |  2KB  |  53 lines

  1. SYNOPSIS
  2.         string regreplace( string txt, string pattern
  3.                          , closure|string replacepattern, int flags)
  4.  
  5. DESCRIPTION
  6.         This function looks through txt looking for the regular
  7.         expression pattern. If it finds it, it replaces it by the
  8.         replacepattern.
  9.  
  10.         The replacepattern can be a constant string, or a closure taking
  11.         the matched substring as argument and returning the replacement
  12.         pattern string.
  13.         
  14.         The flag is a bitmask, where bit 0 specifies
  15.         that the search and replace should repeat as often as the
  16.         pattern matches, and bit 1 (mask 2) specifies if the regular
  17.         expressions are 'ex' compatible or not. The function returns
  18.         the modified string (or the original if it wasn't modified).
  19.  
  20.         The function behaves like the s/pattern/replacepattern/flags
  21.         in editors as ed/vi or sed. The power of this function lies in
  22.         replacing variable strings (as opposed to regexplode, where
  23.         you can explode by regular expression, but not implode...)
  24.  
  25. EXAMPLE
  26.         string msgin;
  27.  
  28.         /* Checks msgin for the string 'tells you: ' and all following
  29.          * characters and encloses those characters by <underline>
  30.          * and </underline>. global.
  31.          */
  32.         msgin = regreplace(msgin, "tells you: (.*)",
  33.                  "tells you: <underline>\\1</underline>", 1);
  34.         
  35.         /* replaces all <underline> html tags by the vt100 escape
  36.          * sequence for underline.
  37.          */
  38.         txt = regreplace(txt, "<underline>", "<ESC>[5m", 1);
  39.  
  40.         /* Put the word HOUSE into lower case. */
  41.         txt = regreplace(txt, "HOUSE", #'lower_case, 1);
  42.  
  43. HISTORY
  44.         Introduced in 3.2.1@125
  45.         The use of a closure as replacepattern was introduced in 
  46.         LDMud 3.2.9.
  47.  
  48. AUTHOR
  49.         Marcus@TAPPMud contributed the original efun and man page
  50.         
  51. SEE ALSO
  52.         regexp(E), regexplode(E), sscanf(E), trim(E)
  53.